package com.lanxin.bx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanxin.bx.entity.BxInformal;
import com.lanxin.bx.mapper.BxInformalMapper;
import com.lanxin.bx.service.IBxInformalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanxin.bx.vo.AllinformalVo;
import com.lanxin.bx.vo.BxinformaldataVo;
import com.lanxin.bx.vo.jobvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author
 * @since 2025-07-18
 */
@Service
public class BxInformalServiceImpl extends ServiceImpl<BxInformalMapper, BxInformal> implements IBxInformalService {

    @Autowired
    private BxInformalMapper bxInformalMapper;

    @Override
    public Page<AllinformalVo> selectbxinformalList(Integer page, Integer pageSize, String docNo, String empName, String submitDate, String status) {
        PageHelper.startPage(page, pageSize);

        List<AllinformalVo> bxInformalList=bxInformalMapper.selectbxinformalList(docNo,empName,submitDate,status);
        return (Page<AllinformalVo>) bxInformalList;
    }

    @Override
    public Page<AllinformalVo> selectmybxinformalList(Integer page, Integer pageSize, String docNo, String submitDate, String status, Integer proposer) {
        PageHelper.startPage(page, pageSize);
        List<AllinformalVo> bxInformalList=bxInformalMapper.selectmybxinformalList(docNo,submitDate,status,proposer);
        return (Page<AllinformalVo>) bxInformalList;
    }

    @Override
    public List<jobvo> selectbxinformalJobList(String deptid) {
        return bxInformalMapper.selectbxinformalJobList(deptid);
    }

    @Override
    public List<BxinformaldataVo> selectbxinformalDataListbytype(String startDate, String endDate) {
        return bxInformalMapper.selectbxinformalDataListbytype(startDate,endDate);
    }

    @Override
    public List<BxinformaldataVo> selectbxinformalDataListbydept(String startDate, String endDate) {
        return bxInformalMapper.selectbxinformalDataListbydept(startDate,endDate);
    }

    //根据部门获取待审批报销申请
    @Override
    public List<BxInformal> getBxinformalByDept(Integer deptId) {
        QueryWrapper<BxInformal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deptid",deptId);
        queryWrapper.eq("status","O");
        return bxInformalMapper.selectList(queryWrapper);
    }

    //根据部门获取所有报销申请
    @Override
    public List<BxInformal> listBxInformalByDept(Integer deptId) {
        QueryWrapper<BxInformal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deptid",deptId);
        return bxInformalMapper.selectList(queryWrapper);
    }

    //修改报销申请的审批状态
    @Override
    public int updateBxStatus(Integer oid, String status) {
        Map<String,Object> map=new HashMap<>();
        map.put("oid",oid);
        map.put("status",status);
        return bxInformalMapper.updateBxStatus(map);
    }
}
